package com.platform.enums;

import com.google.common.collect.Lists;
import com.platform.comm.constants.EnumOption;
import com.platform.comm.enums.IDictEntry;
import com.platform.comm.enums.IEnumItem;
import com.platform.comm.enums.IEnumOption;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 资源信息字段选用状态
 *
 * @author wxw
 * @date 2021/07/28
 */

@EnumOption(name = "dirFieldStatus")
public enum DirFieldStatus implements IDictEntry, IEnumItem, IEnumOption<String> {
    /**
     * 选用
     */
    use("use", "选用"),

    /**
     * 不选用
     */
    ignore("ignore", "不选用");

    public final String code;
    public final String title;

    DirFieldStatus(String code, String title) {
        this.code = code;
        this.title = title;
    }

    /**
     * 根据枚举"键"值解析枚举值
     *
     * @param code 枚举"键"值
     * @return DirFieldStatus
     */
    public static DirFieldStatus parse(String code) {
        return Lists.newArrayList(values())
                .stream()
                .filter(item -> item.is(code))
                .findFirst().orElse(null);
    }

    @Override
    public boolean is(String code) {
        return this.code.equals(code);
    }

    @Override
    public String getKey() {
        return code;
    }

    @Override
    public String getValue() {
        return title;
    }

    @Override
    public Object getData() {
        return this;
    }


    @Override
    public String key() {
        return code;
    }

    @Override
    public String value() {
        return title;
    }

    @Override
    public Map<String, String> enums() {
        return Arrays.stream(values()).collect(Collectors.toMap(IEnumOption::key, IEnumOption::value));
    }
}
